<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head th:replace="common/head :: commonHead('新增流程实例')"></head>

<body>

<div th:replace="common/header :: header"/>

<div class="container-fluid">

    <div class="row-fluid">

        <div th:replace="common/left :: left"/>

        <div class="span9">
            <div class="panel panel-default">
                <div class="panel-heading">
                    Add User
                </div>
                <div class="panel-body">
                    <form class="form-horizontal" role="form" method="post" th:action="@{/user/userAdd}" onsubmit="return checkForm();">
                        <input type="hidden" name="userId" th:value="${userId}">
                        <div class="form-group">
                            <label for="username" class="col-sm-2 control-label">UserName</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="username" name="username"
                                       placeholder="请输入用户名">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="PassWord" class="col-sm-2 control-label">PassWord</label>
                            <div class="col-sm-10">
                                <input type="password" class="form-control" id="PassWord" name="password"
                                       placeholder="请输入密码">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="phone" class="col-sm-2 control-label">Phone</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="phone" name="phone"
                                       placeholder="请输入手机">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="email" class="col-sm-2 control-label">Email</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="email" name="email"
                                       placeholder="请输入邮箱">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Role</label>
                            <div class="col-sm-10">
                                <div class="checkbox" id="role">
                                    <li th:each="role,roleStat : ${roles}">
                                        <input type="checkbox" th:id="roleBox+${role.id}" th:value="${role.id}"></input>
                                        <label th:for="roleBox+${role.id}" th:text="${role.name}"></label>
                                    </li>

                                </div>
                            </div>
                            <input type="hidden" name="roleId" id="roleId">
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="submit" class="btn btn-default">保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>

<div th:replace="common/footer :: footer"/>

<script>

    $(function () {
        $("#role input[type='checkbox']").bind('click', function(){
            var adIds = "";
            $("#role input[type='checkbox']:checked").each(function(i){
                if(0==i){
                    adIds = $(this).val();
                }else{
                    adIds += (","+$(this).val());
                }
            });

            $('#roleId').val(adIds);
        });
    })

    function checkForm() {

        var roleId = $("#roleId").val()
        if(!roleId){
            alert("请选择角色")
            return false;
        }

        return true;

    }
</script>

</body>

</html>



